package com.itheima.threadtest7;

import com.itheima.threadtest6_2.MyThread;

import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 抽奖 并打印
 *
 * java 里面堆内存是唯一的
 * 线程内存不是 每个线程都会有自己的栈   -- 线程栈
 */
public class ThreadDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ArrayList<Integer> list = new ArrayList<>() ;

        Collections.addAll(list , 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25);

        MyCallable myCallable = new MyCallable(list) ;

        FutureTask<Integer> futureTask1 = new FutureTask<>(myCallable) ;
        FutureTask<Integer> futureTask2 = new FutureTask<>(myCallable) ;

        Thread thread1 = new Thread(futureTask1) ;
        Thread thread2 = new Thread(futureTask2) ;

        thread1.start();
        thread2.start();

        thread1.setName("抽奖箱1");
        thread2.setName("抽奖箱2");

        thread1.start();
        thread2.start();

        //设置两个 这样分别代表两个线程的返回值
        Integer max1 = futureTask1.get() ;
        Integer max2 = futureTask2.get() ;

        System.out.println(max1);
        System.out.println(max2);
    }
}
